package com.fr.cell;

import com.fr.base.core.GraphHelper;
import com.fr.base.core.list.IntList;
import com.fr.cell.core.GridUtils;
import com.fr.report.Report;
import com.fr.report.ReportPageAttr;
import com.fr.report.TemplateReport;
import com.fr.report.core.DynamicValueList;
import com.fr.report.core.ReportHelper;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.font.FontRenderContext;
import java.awt.geom.Rectangle2D;
import java.awt.geom.Rectangle2D.Double;
import javax.swing.JComponent;
import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI;

public class GridRowUI extends ComponentUI
{
  private Color detailsBackground = Color.lightGray;

  public void paint(Graphics paramGraphics, JComponent paramJComponent)
  {
    if (!(paramJComponent instanceof GridRow))
      throw new IllegalArgumentException("The component c to paint must be a GridColumn!");
    Graphics2D localGraphics2D = (Graphics2D)paramGraphics;
    GridRow localGridRow = (GridRow)paramJComponent;
    ReportPane localReportPane = localGridRow.getReportPane();
    Dimension localDimension = localGridRow.getSize();
    Rectangle2D.Double localDouble = new Rectangle2D.Double(0.0D, 0.0D, localDimension.getWidth(), localDimension.getHeight());
    localGraphics2D.setPaint(localGridRow.getBackground());
    GraphHelper.fill(localGraphics2D, localDouble);
    FontRenderContext localFontRenderContext = localGraphics2D.getFontRenderContext();
    FontMetrics localFontMetrics = GraphHelper.getFontMetrics(localGridRow.getFont());
    TemplateReport localTemplateReport = localReportPane.getEditingReport();
    DynamicValueList localDynamicValueList = ReportHelper.getRowHeightList(localTemplateReport);
    int i = localReportPane.getGrid().getVerticalValue();
    int j = localReportPane.getGrid().getVerticalBeginValue();
    j = i;
    localReportPane.getGrid().setVerticalBeinValue(j);
    int k = localReportPane.getGrid().getVerticalExtent();
    int l = localTemplateReport.getRowCount() - 1;
    int i1 = i + k + 1;
    double d1 = localDimension.getHeight();
    if (!(localReportPane.isRowEndless()))
    {
      i1 = Math.min(i1, l);
      d1 = localDynamicValueList.getRangeValue(i, Math.max(0, l + 1));
    }
    int i2 = localTemplateReport.getRowCount();
    double d2 = 0.0D;
    localDynamicValueList.getRangeValue(j, i2);
    if (i2 > j)
      d2 = localDynamicValueList.getRangeValue(j, i2);
    d2 = Math.min(d1, d2);
    if (localGridRow.getBackground() != null)
    {
      localGraphics2D.setPaint(this.detailsBackground);
      GraphHelper.fill(localGraphics2D, new Rectangle2D.Double(0.0D, 0.0D, localDimension.getWidth(), d2));
      localGraphics2D.setPaint(localGridRow.getBackground());
      GraphHelper.fill(localGraphics2D, new Rectangle2D.Double(0.0D, d2, localDimension.getHeight(), localDimension.getHeight() - d2));
    }
    localGraphics2D.setPaint(localGridRow.getSeparatorLineColor());
    GraphHelper.drawLine(localGraphics2D, 0.0D, 0.0D, localDimension.getWidth(), 0.0D);
    double d3 = 0.0D;
    double d4 = 0.0D;
    double d5 = 0.0D;
    for (int i4 = 0; i4 <= i1; ++i4)
    {
      int i3;
      if (i4 == 0)
        i4 = j;
      d3 += d5;
      d5 = localDynamicValueList.get(i4);
      if (d5 == 0.0D)
        d4 = d3 + 1.0D;
      else
        d4 = d3 + d5;
      GridSelection localGridSelection = localReportPane.getGridSelection();
      IntList localIntList = GridUtils.getGridSelectionRowIndex(localGridSelection);
      int i5 = localGridSelection.getType();
      if ((i5 == 0) && (localIntList.contain(i4)))
      {
        localGraphics2D.setPaint(localGridRow.getSelectedBackground());
        GraphHelper.fill(localGraphics2D, new Rectangle2D.Double(0.0D, d3 + 1.0D, localDimension.width, d5 - 1.0D));
        i3 = 1;
      }
      else
      {
        i3 = 0;
      }
      localGraphics2D.setColor(localGridRow.getSeparatorLineColor());
      GraphHelper.drawLine(localGraphics2D, 0.0D, d4, localDimension.getWidth(), d4);
      Object localObject = localGridRow.getGridCRRender().getDisplay(i4);
      if (localObject == null)
        return;
      if ((localObject instanceof String) || (localObject instanceof Number))
      {
        String str = localObject.toString();
        if (localTemplateReport.getReportPageAttr() != null)
        {
          if ((i4 >= localTemplateReport.getReportPageAttr().getRepeatHeaderRowFrom()) && (i4 <= localTemplateReport.getReportPageAttr().getRepeatHeaderRowTo()))
            str = str + "(H)";
          if ((i4 >= localTemplateReport.getReportPageAttr().getRepeatFooterRowFrom()) && (i4 <= localTemplateReport.getReportPageAttr().getRepeatFooterRowTo()))
            str = str + "(F)";
        }
        float f = localFontMetrics.getAscent();
        double d6 = localGridRow.getFont().getStringBounds(str, localFontRenderContext).getWidth();
        if (i3 != 0)
          localGraphics2D.setColor(localGridRow.getSelectedForeground());
        else if (localGridRow.isEnabled())
          localGraphics2D.setColor(localGridRow.getForeground());
        else
          localGraphics2D.setPaint(UIManager.getColor("controlShadow"));
        GraphHelper.drawString(localGraphics2D, str, (localDimension.width - d6) / 2.0D, d3 + 2.0D + f);
      }
      else if (localObject instanceof Image)
      {
        GraphHelper.paintImage(localGraphics2D, localDimension.width, (int)d5, (Image)localObject, null, 3, -1, -1);
      }
    }
    localGraphics2D.setColor(localGridRow.getSeparatorLineColor());
    GraphHelper.drawLine(localGraphics2D, 0.0D, 0.0D, 0.0D, d4);
  }
}